package chapter06;

import java.util.concurrent.TimeUnit;

/**
 * @author chisheng
 * @since 2021-11-11
 */
public class ThreadGroupBasic {

    public static void main(String[] args) throws InterruptedException {
        ThreadGroup myGroup = new ThreadGroup("myGroup");
        Thread myThread = new Thread(myGroup, () -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "myThread");
        myThread.start();

        TimeUnit.MILLISECONDS.sleep(2);

        ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();
        System.out.println("activeCount: " + mainGroup.activeCount());
        System.out.println("activeGroupCount: " + mainGroup.activeGroupCount());
        System.out.println("getMaxPriority: " + mainGroup.getMaxPriority());
        System.out.println("getName: " + mainGroup.getName());
        System.out.println("getParent: " + mainGroup.getParent());
        System.out.println("===================================");
        mainGroup.list();
        System.out.println("===================================");
        System.out.println("parentOf(myGroup): " + mainGroup.parentOf(myGroup));
        System.out.println("parentOf(mainGroup): " + mainGroup.parentOf(mainGroup));
    }

}
